package net.neptech.utils;

import net.neptech.model.vo.ClnicStaffVo;

import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 日期工具类
 */
public class DateUtils {
    /**
     * 获取未来日期
     * @param date
     * @param dayNum
     * @return
     */

    public  static Date getFutureDate(Date date,int dayNum ){

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_YEAR, dayNum);
        return cal.getTime();
    }
    /**
     * 获取起始查询时间 大于12点小于12点 则转换成 12点。小于12点则转换成0点
     */
    public static Date getStartTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        if (hour >= 12) {
            return target(date, 12, 0, 0, 0);
        } else {
            return target(date, 0, 0, 0, 0);
        }
    }


    /**
     * 转换目标时间
     * @param date
     * @return
     */
    public static Date target(Date date,Integer h,Integer m,Integer s,Integer ms){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, h);
        cal.set(Calendar.MINUTE, m);
        cal.set(Calendar.SECOND, s);
        cal.set(Calendar.MILLISECOND, ms);
        return cal.getTime();
    }

    /**
     * 获取当前时间加30分钟
     */
    public static Date getCurrentTimePlusMinutes(Integer minus) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE, minus);
        return cal.getTime();
    }
    /**
     * 时间合并
     */
    public static Date mergeDateAndTime(Date dd, Time tt) {

        ZoneId zone = ZoneId.of("Asia/Shanghai");
        LocalDate d = dd.toInstant().atZone(zone).toLocalDate();
        LocalTime t = tt.toLocalTime();
        return Date.from(LocalDateTime.of(d, t).atZone(zone).toInstant());
    }
}
